package jvm;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

import java.time.LocalDate;

/**
 * @author wanyuxiang
 * @version 1.0
 * @project Java_base
 * @create 2017-05-05 12:29
 * @desc -XX:PermSize=10M -XX:MaxPermSize=10M 在JDK6的时候会抛出OutOfMemoryError
 **/
public class JavaMethodAreaOOM {
    public static void main(String[] args) {
        while (true) {
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(OOMObject.class);
            enhancer.setUseCache(false);
            enhancer.setCallback((MethodInterceptor) (obj, method, as, proxy) -> proxy.invokeSuper(obj, as));
            Object obj = enhancer.create();
            ((OOMObject) obj).aa();
        }
    }

    private static class OOMObject {
        public OOMObject() {

        }

        public void aa() {
            System.out.println(this + "->" + LocalDate.now());
        }
    }
}
